/*************************************************************************
	> File Name: protocol.h
	> Author: xuwenlong
	> Mail: myxuan475@126.com 
	> Created Time: 2018年01月23日 星期二 16时33分29秒
 ************************************************************************/

#include<stdio.h>
#include "jsonbuffer.h"
#include "../../transport.h"
#include <utils/logger.h>
#include <utils/timer.h>

class RPCProtocol:public ProtocolInterface
{
public:
    RPCProtocol(TransportInterface *interface,
            bool isEncrypt = false);

    virtual ~RPCProtocol();
    virtual void Init();
    void AppendTransport(
            TransportInterface *interface);

    virtual void ClearRecvData();

    virtual void RpcParse();

    void OnReceiveData(
            void *data,int length);

    void OnMessage(Json::Value &jsonObj);
    virtual BOOL SendError(
            int msgId,
            const std::string& method,
            const Json::Value &result, const char *error);

    virtual BOOL SendRequest(
            int msgId,
            const std::string& method,
            const Json::Value &params);

    virtual BOOL SendResult(
            int msgId,
            const std::string& method,
            const Json::Value &result);

    virtual void *GetTask(DAS_TASK task);
    virtual int GetIndex();
    virtual const std::string GetSection();

protected:
    BOOL sendJson(const Json::Value &data);
private:
    LOG_MODULE_TRACE(RPCProtocol);
    JsonBuffer m_jsonBuffer;
    bool       m_bEncrypt;
protected:
    TransportInterface * m_pTransport;
};
